#ifndef WIN32_UTILITY_HPP
#define WIN32_UTILITY_HPP

#ifndef WIN32
#error "This file must use under Windows platform!"
#endif

#include <Windows.h>
#include <string>

namespace Win32 {
    inline std::string toUtf8(const std::wstring &wide_string) {
        std::string result;

        int length = WideCharToMultiByte(CP_UTF8, 0, wide_string.data(), -1, nullptr, 0, nullptr, nullptr);
        result.resize(length + 1);
        length = WideCharToMultiByte(CP_UTF8, 0, wide_string.data(), -1, &result[0], length, nullptr, nullptr);
        result[length] = 0;
        result.resize(length - 1);

        return result;
    }
    inline std::wstring fromUtf8(const std::string &u8_string) {
        std::wstring result;

        int length = MultiByteToWideChar(CP_ACP, 0, u8_string.data(), -1, nullptr, 0);
        result.resize(length + 1);
        length = MultiByteToWideChar(CP_ACP, 0, u8_string.data(), -1, &result[0], length);
        result[length] = 0;
        result.resize(length - 1);

        return result;
    }
}

#endif// WIN32_UTILITY_HPP
